<template>
  <div class="main_spac1">
    <div class="main_white padding10 paddingTop10">
      <div class="mainor_form">
        <el-form
          :inline="true"
          :model="form"
          class="demo-form-inline"
          ref="userListFrom"
          label-width="120px"
        >
          <el-form-item label="档口名称" prop="uid">
            <el-input
              v-model.trim="form.nickname"
              placeholder="档口名称"
              clearable
              class="wid220"
            ></el-input>
          </el-form-item>
          <el-form-item label="配送日期" prop="sendTime">
            <el-date-picker
              v-model="sendTime"
              type="daterange"
              class="time220"
              :editable="false"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              :clearable="false"
              :picker-options="pickerOptions"
              @change="getArticleList"
            />
          </el-form-item>
          <!-- <el-form-item
            label="供应商名称"
            prop="goods_spu_id"
            style="margin-right: 0"
          >
            <el-input
              v-model.trim="form.company_name"
              placeholder="供应商名称"
              clearable
              class="wid220"
            ></el-input>
          </el-form-item> -->
          <div class="more el-form-item" @click="more">
            <span>更多</span>
            <i :class="[{ on: moredata }, ' el-icon-arrow-down']"></i>
          </div>
          <div class="clearfix"></div>
          <el-collapse-transition>
            <div v-if="moredata" style="width: 100%">
              <!-- <el-form-item label="商品名称" prop="uid">
                <el-input
                  v-model.trim="form.goods_name"
                  placeholder="商品名称"
                  clearable
                  class="wid220"
                ></el-input>
              </el-form-item> -->
              <el-form-item label="订单号" prop="order_sn">
                <el-input
                  v-model.trim="form.order_sn"
                  placeholder="订单号"
                  clearable
                  class="wid220"
                ></el-input>
              </el-form-item>
              <div class="clearfix"></div>
            </div>
          </el-collapse-transition>
          <el-form-item class="marginTop10">
            <el-button class="reset marginLeft10" type="primary" @click="reset"
              >重置</el-button
            >
            <el-button
              type="primary"
              @click="getArticleList"
              :loading="listLoading"
              >搜索</el-button
            >
          </el-form-item>
        </el-form>
      </div>

      <div class="main_table" style="min-height: 530px">
        <el-table
          ref="multipleTable"
          v-loading="listLoading"
          :data="listData"
          element-loading-text="加载中"
          fit
          border
          highlight-current-row
          @selection-change="handleSelectionChange"
          :header-cell-class-name="this.$verticaline"
          :height="handleScrool"
        >
          <el-table-column type="selection" />
          <el-table-column
            label="配送日期"
            width="150"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">{{
              parseTime(scope.row.send_time, "{y}-{m}-{d}")
            }}</template>
          </el-table-column>
          <el-table-column
            label="订单状态"
            prop="order_status"
            width="100"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span :class="`status${scope.row.order_status}`">{{orderStatus[scope.row.order_status]}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="档口名称"
            prop="nickname"
            :show-overflow-tooltip="true"
            width="120"
          >
            <template slot-scope="scope"
              >{{
                scope.row.member
                  ? scope.row.member.nickname
                  : scope.row.nickname
              }}<span v-if="scope.row.zid_info"
                >【{{ scope.row.zid_info.nickname }}】</span
              ></template
            >
          </el-table-column>
          <el-table-column label="下单日期" width="150">
            <template slot-scope="scope">{{
              parseTime(scope.row.created_at, "{y}-{m}-{d}")
            }}</template>
          </el-table-column>
          <el-table-column
            label="订单号"
            prop="order_sn"
            :show-overflow-tooltip="true"
            width="150"
          />
          <el-table-column label="支付状态" width="100" prop="pay_status">
            <template slot-scope="scope">
              <span :class="scope.row.pay_status==1?'success':'fail'">{{scope.row.pay_status==1?"已支付":'未支付'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="司机" prop="driver_id"></el-table-column>
          <el-table-column
            label="收货地址"
            prop="address"
            width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="收货手机" prop="mobile" />
          <el-table-column label="收货人" prop="contact" />
          <el-table-column
            label="管理操作"
            align="right"
            fixed="right"
            width="240"
            class-name="main_hei"
          >
            <template slot-scope="scope">
              <router-link :to="'/order/list/see/' + scope.row.id">
                <el-link type="success">查看</el-link>
              </router-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="main_page boxdq">
        <div class="main_num boxdq">
          <div class="main_num_l boxha">
            <p>
              新增订单：
              <em>{{ list.today_order_num || 0 }}</em>
            </p>
          </div>
        </div>
        <!-- 分页 -->
        <div class="main_page_r" ref="mainpage">
          <el-pagination
            :current-page="current.page"
            :page-sizes="[10 ,20 ,30 , 50, 100]"
            :page-size="limit"
            layout="->,total, sizes, prev, pager, next, jumper"
            :total="totalCount"
            background
            @size-change="changeLimit"
            @current-change="changePage"
          />
        </div>
      </div>
    </div>

    <!-- 订单导出 -->
    <el-dialog
      title="订单导出"
      :visible.sync="exportbuVisible"
      class="main_dialog dialog500"
    >
      <div v-if="selectArr.length == 0 ? true : false">
        <p class="exptitle">选择配送日期</p>
        <el-date-picker
          v-model="exportTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change="dateChange"
        >
        </el-date-picker>
        <el-tooltip
          class="item"
          effect="dark"
          content="时间范围只能选择一个月之内"
          placement="top"
        >
          <i class="el-icon-question"></i>
        </el-tooltip>
        <p class="exptitle" style="padding-top: 10px">用户</p>
        <change-user-input
          ref="changeUserInput"
          @sendValue="getUser"
          @clear="clearUid"
        ></change-user-input>
        <p class="exptitle" style="padding-top: 10px">订单状态</p>
        <el-select
          v-model.trim="export_status"
          class="wid240"
          placeholder="订单状态"
          multiple
          clearable
        >
          <el-option label="待审核" value="0"></el-option>
          <el-option label="备货中" value="1"></el-option>
          <el-option label="配送中" value="2"></el-option>
          <el-option label="已收货" value="3"></el-option>
          <el-option label="已取消" value="4"></el-option>
        </el-select>
      </div>
      <div>
        <p class="exptitle margintop">选择导出订单信息字段</p>
        <div>
          <el-checkbox-group v-model="exportHeaderType.orderList">
            <el-checkbox
              v-for="(Header, index) in exportOrderLsit"
              :key="index"
              :label="Header.id"
              :disabled="Header.disabled"
              >{{ Header.name }}</el-checkbox
            >
          </el-checkbox-group>
        </div>
        <div>
          <el-checkbox v-model="goodspicker"
            >导出商品信息
            <el-tooltip
              class="item"
              effect="dark"
              content="默认不勾选，则不导出商品信息"
              placement="top"
            >
              <i class="el-icon-question"></i> </el-tooltip
          ></el-checkbox>
        </div>
      </div>
      <div v-if="goodspicker">
        <p class="exptitle margintop">选择导出商品字段信息</p>
        <el-checkbox-group v-model="exportHeaderType.goodsList">
          <el-checkbox
            v-for="(Header, index) in exportGoodsList"
            :key="index"
            :label="Header.id"
            >{{ Header.name }}</el-checkbox
          >
        </el-checkbox-group>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="exportbuVisible = false">取 消</el-button>
        <el-button type="primary" @click="exportConfirm" v-repeatClick
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 打印子组件 -->
    <order-print
      ref="printTemplate"
      v-show="false"
      id="printname"
    ></order-print>
  </div>
</template>

<script>
import dateOption from "@/options/dateOption";
import {
  order_index,
  order_splitCate,
  order_split,
  order_info,
  order_setOrderStatus,
  order_merge,
  order_batchReceive,
  order_export_info,
  order_export,
  order_info_detail,
  order_down_tem,
} from "@/api/order/orderList";
import {
  field_save,
  setting_company,
  goods_getGoodsSpu,
  order_import,
} from "@/api/currency";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime, exportMethod, getNowMonth } from "@/utils/index";
import { orderListHeader, GoodsList } from "@/options/headerSet.js";
import OrderPrint from "@/views/order/orderPrint.vue";
import { mapGetters } from "vuex";
import commissionPayVue from "../index/commissionPay.vue";
export default {
  components: {
    OrderPrint,
  },

  computed: {
    ...mapGetters(["avatar"]),
    reverseSum() {
      return this.percent_list;
    },
    send_percent() {
      let percent = 0;
      if (this.list.today_sent_num != 0) {
        percent = parseFloat(
          (this.list.today_sent_num / this.list.today_send_num) * 100
        ).toFixed(2);
      }
      return Number(percent);
    },
    isShow_edit() {
      return (scope) => {
        if (scope.row.order_status == 0 || scope.row.order_status == 1) {
          if (scope.row.is_prior_payment == 1 && scope.row.order_status == 0) {
            return false;
          }
          return true;
        } else {
          return false;
        }
      };
    },
    isShow_export() {
      return (scope) => {
        if (
          scope.row.order_status == 3 ||
          (scope.row.order_status == 1 && scope.row.is_prior_payment == 1)
        ) {
          if (scope.row.order_status == 0 || scope.row.order_status == 1) {
            return false;
          }
          return true;
        } else {
          return false;
        }
      };
    },
    orderStatus(){
      return{
        0:"待审核",
        1:"备货中",
        2:"配送中",
        3:"已完成",
        4:"已取消"
      }
    }
  },
  data() {
    return {
      handleScrool: "620px",
      exportMethod,
      getNowMonth,
      order_import: order_import,
      // 打印id
      printid: "",
      // 拆分
      splitVisible: false,
      split_sh: [],
      // 审核
      examineVisible: false,
      examine_sh: {
        member: {
          nickname: "",
        },
      },
      split_chec: [],
      // 时间
      parseTime,
      // 分页
      current: {
        page: 1,
        page_size: 10,
      },
      limit: 10,
      totalCount: 1,
      // 列表数据
      list: {
        today_sent_num: 0,
        today_send_num: 1,
        from_list: [],
        group: [],
        is_delivery: [],
        is_piroment: [],
        is_print_list: [],
        order_status_list: [],
        pay_type_list: [],
        salesman: [],
        driver: {},
        list: {
          data: [],
        },
      },
      listLoading: false,
      // 搜索
      form: {
        send_start_time: "", //配送日期
        send_end_time: "",
        order_sn: "",
        uid: "",
        from: "", //来源
        is_delivery_id: "", //运费
        is_piroment_id: "", //支付方式
        is_print: "",
        goods_spu_id: "", //商品
        send_time_id: null,
        create_start_time: "", //下单日期
        create_end_time: "",
        contact: "", //收货信息
        group_id: null,
        salesman_id: "", //业务员
        driver_id: "", //司机
        mobile: "",
        pay_type: null, //支付状态
        status: this.activeName,
        nickname: "",
      },
      createTime: [],
      sendTime: [],
      pickerOptions: dateOption,
      look_canceled_list: false,
      // 选中菜单
      activeName: null,
      // 更多
      moredata: false,
      // 全选
      selectArr: [],
      // 表头设置
      dialogFormVisible: false,
      type: [],
      Header: orderListHeader,
      // id
      id: "",

      // 订单导出
      exportbuVisible: false,
      goodspicker: false, //商品信息 true
      exportOrderLsit: orderListHeader,
      exportGoodsList: GoodsList,
      // 默认的导出表头信息
      exportHeaderType: {
        orderList: [],
        goodsList: [],
      },
      // 订单导出时间
      exportTime: [],
      export_user: "",
      export_status: [],
      // 订单导入
      importbuVisible: false,
      import_form: {
        user_type: 1,
        goods_type: 1,
        start_line_num: 2,
        end_line_num: "",
      },
      import_file_name: "",
      import_params: {
        string: "",
        admin_uid: "",
        admin_uid_company: "",
      },
      percent_gs: 0,
      percent: 0,
      percentShow: false,
      percent_list: [],
      importArrLength: 1,
      cancelDisabled: false,

      listData: [
        {
          order_sn: 100000,
          nickname: "张三猪肉铺",
          created_at: "2023-8-8",
          send_time: "2023-8-9",
          order_status: "待配送",
          contact: "小徐",
          mobile: "15707053563",
          driver_id: "马师傅",
          address: "测试地址",
        },
      ],
    };
  },
  activated() {
    // 列表
    this.order_index();
    this.handleScroll();
  },
  // 刷新
  inject: ["reload"],

  methods: {
    // 勾选
    canceledChange(val) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, { look_canceled_list: val ? 1 : 0 })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { look_canceled_list: val ? 1 : 0 }
      );
      setting_company(data).then((res) => {
        if (res.errcode == 0) {
          this.order_index();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 拆分
    order_splitCate() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      order_splitCate(data).then((res) => {
        if (res.errcode == 0) {
          this.split_sh = res.data.category;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    split() {
      if (this.split_chec.length != 0) {
        let data = Object.assign(
          {
            sign: Md5(
              objKeySort(
                Object.assign(apiUrl().name, {
                  id: this.id,
                  cate: JSON.stringify(this.split_chec),
                })
              ) + apiUrl().appsecret
            ),
          },
          apiUrl().name,
          { id: this.id, cate: JSON.stringify(this.split_chec) }
        );
        order_split(data).then((res) => {
          if (res.errcode == 0) {
            this.$message({
              message: "拆分成功",
              type: "success",
            });
            this.split_chec = [];
            this.splitVisible = false;
            this.order_index();
          } else {
            this.$message.error(res.errmsg);
          }
        });
      } else {
        this.$message.error("请选择拆分分类");
      }
    },
    // 审核
    order_info() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      order_info(data).then((res) => {
        if (res.errcode == 0) {
          this.examine_sh = res.data.info;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    examine(type, is_receipt) {
      let form = {
        id: this.id,
        status: type,
        is_receipt: is_receipt,
      };
      is_receipt ? "" : delete form.is_receipt;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, { id: this.id, status: type })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      order_setOrderStatus(data).then((res) => {
        if (res.errcode == 0) {
          if (type == 1) {
            this.$message({
              message: "审核成功",
              type: "success",
            });
          } else if (type == 3) {
            this.$message({
              message: "确认成功",
              type: "success",
            });
          } else {
            this.$message({
              message: "取消成功",
              type: "success",
            });
          }
          this.order_index();
          this.examineVisible = false;
        } else if (res.errcode == 40035) {
          let msg = res.errmsg;
          this.examineVisible = false;
          this.$nextTick(() => {
            this.$alert(msg, "提示", {
              confirmButtonText: "确定",
              callback: (action) => {
                this.order_index();
              },
            });
          });
        } else {
          this.$message.error(res.errmsg);
          this.examineVisible = false;
        }
      });
    },
    examine_edit() {
      this.examineVisible = false;
      this.$router.push("/order/list/edit/" + this.id);
    },
    // 取消
    cancelClick() {
      this.$confirm("确认取消订单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.examine(4);
        })
        .catch(() => {});
    },
    // 收货
    successClick() {
      this.$myConfirm("确认订单用户已完成签收?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        threesButtonText: "确认并回单",
        type: "warning",
      })
        .then((val) => {
          if (val == 1) {
            this.examine(3);
          } else if (val == 2) {
            this.examine(3, 1);
          }
        })
        .catch(() => {});
      // this.$confirm("确认订单用户已完成签收?", "提示", {
      // 	confirmButtonText: "确定",
      // 	cancelButtonText: "取消",
      // 	type: "warning",
      // })
      // 	.then(() => {
      // 		this.examine(3);
      // 	})
      // 	.catch(() => {});
    },
    // 回单
    receipt(id) {
      this.id = id;
      this.$confirm("确认该订单已经回单吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.examine(3, 1);
        })
        .catch(() => {});
    },
    // 退货
    quit(scope) {
      let uid = scope.row.uid;
      let id = scope.row.id;
      let return_status = scope.row.return_status;
      if (return_status == 2) {
        this.$message.warning("订单已全部退货，无法再继续退货！");
        return;
      }
      this.$router.push({
        name: "order_return_add",
        params: { uid: uid, id: id, return_status: return_status },
      });
    },

    // 选中菜单
    handleClick(tab, event) {
      this.form = {
        send_start_time: "", //配送日期
        send_end_time: "",
        order_sn: "",
        uid: "",
        from: "", //来源
        is_delivery_id: "", //运费
        is_piroment_id: "", //支付方式
        is_print: "",
        goods_spu_id: "", //商品
        send_time_id: null,
        create_start_time: "", //下单日期
        create_end_time: "",
        contact: "", //收货信息
        group_id: null,
        salesman_id: "", //业务员
        driver: "", //司机
        mobile: "",
        pay_type: null, //支付状态
      };
      if (this.$refs["changeUserInput_form"]) {
        this.$refs["changeUserInput_form"].name = "";
      }
      this.current.page = 1;
      this.current.page_size = 10;
      this.limit = 20;
      this.order_index();
    },
    // 更多
    more() {
      this.moredata = !this.moredata;
      this.handleScroll();
    },
    // 监听全选
    handleSelectionChange(val) {
      this.selectArr = [];
      val.map((item) => {
        this.selectArr.push({ id: item.id });
      });
    },
    // 合并订单
    merge() {
      if (this.selectArr.length != 0) {
        this.$confirm("确定合并订单?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            let data = Object.assign(
              {
                sign: Md5(
                  objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
                ),
              },
              apiUrl().name,
              { ids: JSON.stringify(this.selectArr) }
            );
            order_merge(data).then((res) => {
              if (res.errcode == 0) {
                this.$message({
                  message: "合并成功",
                  type: "success",
                });
                this.order_index();
              } else {
                this.$message.error(res.errmsg);
              }
            });
          })
          .catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 批量收货
    bulkGoods() {
      if (this.selectArr.length != 0) {
        let length = this.selectArr.length;
        let ids = this.selectArr.map((e) => {
          return e.id;
        });
        let form = {
          ids: ids.join(","),
        };
        this.$myConfirm(`确认批量完成【${length}】条订单？`, "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          threesButtonText: "确认并回单",
          type: "warning",
        })
          .then((val) => {
            if (val == 1) {
              this.batchReceive(form, 1);
            } else if (val == 2) {
              form.is_receipt = 1;
              this.batchReceive(form, 2);
            }
          })
          .catch(() => {});
        // this.$confirm(`确认批量完成【${length}】条订单？`, "提示", {
        // 	confirmButtonText: "确定",
        // 	cancelButtonText: "取消",
        // 	type: "warning",
        // })
        // 	.then(() => {
        // 		this.order_batchReceive(form);
        // 	})
        // 	.catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 批量回单
    bulkReceipt() {
      if (this.selectArr.length != 0) {
        let length = this.selectArr.length;
        let ids = this.selectArr.map((e) => {
          return e.id;
        });
        let form = {
          ids: ids.join(","),
          is_receipt: 1,
        };
        this.$confirm(`已选中【${length}】条订单，确认都已回单？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.batchReceive(form, 3);
          })
          .catch(() => {});
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 批量收货&&批量回单请求
    batchReceive(form, type) {
      let message = {
        1: "批量收货已完成",
        2: "批量收货并已回单",
        3: "批量回单已完成",
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      order_batchReceive(data).then((res) => {
        if (res.errcode == 0) {
          this.$message({
            message: message[type],
            type: "success",
          });
          this.order_index();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 导出框
    exportb() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name
      );
      order_export_info(data).then((res) => {
        if (res.errcode == 0) {
          this.exportHeaderType.orderList = res.data.list.type_10;
          this.exportHeaderType.goodsList = res.data.list.type_11;
        }
        this.exportbuVisible = true;
      });
    },
    // 下载模板
    downTemplate() {
      let form = {
        user_type: this.import_form.user_type,
        goods_type: this.import_form.goods_type,
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      order_down_tem(data).then((res) => {
        this.exportMethod(res, "订单导入模板");
      });
    },
    // 导入订单
    importDialog() {
      this.import_file_name = "";
      this.percent_gs = 0;
      this.percent = 0;
      this.percentShow = false;
      this.percent_list = [];
      this.importArrLength = 1;
      this.cancelDisabled = false;
      this.importbuVisible = true;
    },

    importerr(err, file, fileList) {
      this.$message.error("上传失败");
    },
    importSuccess(response, file, fileList) {
      if (response.code == 100) {
        this.$message.warning(response.msg);
        return;
      }
      this.import_file_name = file.name;
    },
    handleUpload() {
      this.import_params.string =
        this.import_form.start_line_num + "," + this.import_form.end_line_num;
    },
    //获取用户信息
    getUser(data) {
      let uid = data.info.user_id;
      this.export_user = uid;
    },
    // 清除用户的uid
    clearUid() {
      this.export_user = "";
    },
    exportConfirm() {
      // 订单表头
      let orderList = [];
      this.exportOrderLsit.map((e) => {
        this.exportHeaderType.orderList.map((p) => {
          if (e.id == p) {
            orderList.push(e.id);
            return;
          }
        });
      });
      let goodsList = [];
      this.exportGoodsList.map((e) => {
        this.exportHeaderType.goodsList.map((p) => {
          if (e.id == p) {
            goodsList.push(e.id);
            return;
          }
        });
      });
      let ids = [];
      if (this.selectArr.length > 0) {
        this.selectArr.forEach((item) => {
          ids.push(item.id);
        });
      }
      let time = "";
      if (this.exportTime) {
        time = this.exportTime.join(" ");
      }
      let form = {
        ids: ids.join("-"),
        order_head: orderList.join("-"),
        list_head: goodsList.join("-"),
        is_status: this.goodspicker ? 1 : 0,
        send_time: time,
        export_user: this.export_user,
        status: this.export_status.join(","),
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, form)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      if (!data.send_time && !data.ids) {
        this.$message.warning("请选择导出的配送时间段或导出的订单");
        return false;
      }
      // 储存导出的订单字段
      let data2 = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { type: 10 })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          type: 10,
          fields: JSON.stringify(orderList),
        }
      );
      // 储存导出的商品字段
      let data3 = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { type: 11 })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          type: 11,
          fields: JSON.stringify(goodsList),
        }
      );
      field_save(data2).then((res) => {
        if (res.errcode != 0) {
          // this.$message.error(res.errmsg);
        }
      });
      field_save(data3).then((res) => {
        if (res.errcode != 0) {
          // this.$message.error(res.errmsg);
        }
      });
      // 导出数据
      order_export(data).then((res) => {
        this.exportMethod(res, "订单列表");
      });
      this.exportbuVisible = false;
    },
    // 日期选择
    dateChange(val) {
      let start = new Date(val[0]).getTime();
      let end = new Date(val[1]).getTime();
      let diff = start - end;
      if (Math.abs(diff) > 3600 * 1000 * 24 * 60) {
        this.$message.warning("选择时间跨度不能超过两个月");
        this.exportTime = this.getNowMonth();
      }
    },
    // 详情导出
    // 导出
    exportOrderiInfo(id) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: id }
      );

      order_info_detail(data)
        .then((res) => {
          this.exportMethod(res, "订单详情");
        })
        .catch(() => {
          this.$message.error("导出失败");
        });
    },
    // 打印
    print(id, uid) {
      // this.$message.error("12/18  接口待完善待添加");
      this.printid = id;

      this.$refs.printTemplate.$emit("demo", {
        id: id,
        uid: uid,
        type: "order",
      });
    },
    // 设置确认
    setupmine(val) {
      let arry = [];
      this.Header.map((e) => {
        this.type.map((p) => {
          if (e.id == p) {
            arry.push(e.id);
            return;
          }
        });
      });
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { type: 5 })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          type: 5,
          fields: JSON.stringify(arry),
        }
        // [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
      );
      field_save(data).then((res) => {
        if (res.errcode == 0) {
          this.$message({
            message: "设置成功",
            type: "success",
          });
          this.reload();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.order_index()
    },
    // 重置
    reset() {
      this.$refs["userListFrom"].resetFields();
      if (this.$refs["changeGoodsInput"]) {
        this.$refs["changeGoodsInput"].name = "";
      }
      if (this.$refs["changeUserInput_form"]) {
        this.$refs["changeUserInput_form"].name = "";
      }
      this.createTime = [];
      this.sendTime = [];
      this.order_index();
      this.form.nickname = "";
      this.form.order_sn = "";
    },
    // 分页
    changeLimit(pageSize) {
      this.current.page_size = pageSize;
      this.order_index();
    },
    changePage(page) {
      this.current.page = page;
      this.order_index();
    },
    // 列表
    order_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name) ,this.list_form()) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current,
      );
      order_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          // console.log("res", res);
          this.listData = res.data.list.data;
          this.list.today_order_num = res.data.today_order_num;
          this.totalCount = res.data.list.total;
          // 在数据更新后执行
          this.$nextTick(() => {
            // myTable是表格的ref属性值
            if (this.$refs.multipleTable && this.$refs.multipleTable.doLayout) {
              this.$refs.multipleTable.doLayout();
            }
          })
          return;
          res.data.list.data.map((e) => {
            e.usercode = e.member.info.code;
            let gs = 3;
            if (e.order_status == 0) {
              gs += 4;
            }
            if (e.order_status == 1) {
              gs += 3;
            }
            if (e.order_status == 2) {
              gs += 2;
            }
            if (e.order_status == 3) {
              gs += 1;
            }
            e.total = gs;

            e.show = false;
          });

          this.look_canceled_list =
            res.data.look_canceled_list == 1 ? true : false;
          this.type = res.data.field;
          this.list = res.data;
          this.import_params.admin_uid = res.data.admin_uid;
          this.import_params.admin_uid_company = res.data.admin_uid_company;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
        // company_name
        // goods_name 
      let form={
        nickname:this.form.nickname,
        order_sn:this.form.order_sn
      }
      form.send_start_time = this.sendTime[0] ? this.sendTime[0] : "";
      form.send_end_time = this.sendTime[1] ? this.sendTime[1] : "";
      form.create_start_time = this.createTime[0] ? this.createTime[0] : "";
      form.create_end_time = this.createTime[1] ? this.createTime[1] : "";
      return form;
    },
    // 底部到视口顶部的距离
    handleScroll() {
      const distance = window.innerHeight - 350;
      const dastsdf = window.innerHeight - 310;
      this.moredata == true
        ? (this.handleScrool = distance + "px")
        : (this.handleScrool = dastsdf + "px");
      // console.log(this.handleScrool);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.el-dropdown-menu--small .el-dropdown-menu__item {
  padding: 2px 20px;
}

.main_ti {
  margin-bottom: 15px;
  padding-bottom: 1px;
  position: relative;

  /deep/.el-tabs__header {
    margin: 0;
  }

  /deep/.el-checkbox {
    margin-top: 12px;
  }

  &::after {
    height: 1px;
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: #e4e7ed;
    z-index: 1;
  }

  /deep/.el-tabs__nav-wrap::after {
    height: 0;
  }
}

.main_dialog {
  .main_table {
    /deep/.el-table__body-wrapper {
      overflow-y: auto;
      height: 300px;
    }
  }

  .main_xq ul li {
    width: 33.33%;
    margin-top: 5px;
    margin-bottom: 5px;
  }

  .examine_he {
    font-size: 16px;
    text-align: right;
    margin-top: 20px;

    span {
      color: red;
    }
  }
}

// 导出订单表头
.exptitle {
  display: block;
  font-size: 16px;
  color: #000000;
  margin: 0 0 10px;
  cursor: pointer;
}

.margintop {
  padding-top: 15px;
}

.el-checkbox-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;

  .el-checkbox {
    width: 26%;
  }
}

// 导入进度条
.import_process {
  width: 100%;
}

.progress {
  padding: 15px 40px 15px 0;
  // display: flex;
  // justify-content: center;
  // align-items: center;
}

.notice {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding-right: 40px;

  .importtips {
    overflow-y: auto;
    width: 100%;
    height: 84px;
    height: 84px;
    background: #ffffff;
    border: 1px solid #d8d8d8;
    padding: 10px 15px;

    .fail {
      color: #ff5a5a;
      line-height: 1.2;
      font-size: 12px;
    }

    .success {
      color: #19b098;
      line-height: 1.2;
      font-size: 12px;
    }
  }
}

// 支付状态
.success {
  color: $green;
}
.fail {
  color: #ff5a5a;
}
.unpaid {
  color: $colour_red;
}

// 订单状态
.order1 {
  color: $order_color1;
}

.order2 {
  color: $order_color2;
}

.order3 {
  color: $order_color3;
}

.order4 {
  color: $order_color4;
}

// 打印状态
.is_print0 {
  color: $colour_red;
}

.is_print1 {
  color: $green;
}

// 支付方式
.pay_type0 {
  color: $order_color1;
}

.pay_type1 {
  color: $green;
}

.new_navbar_svg {
  margin-left: 5px;
}

.temporary_svg {
  vertical-align: bottom;

  use {
    fill: #585858;
  }
}

/deep/.main_table .el-table--small td.main_hei .cell {
  display: flex;
  justify-content: flex-start;
  flex-direction: row-reverse;
  align-items: center;
}
.status0 {
  color: #f55726;
}
.status1{
  color: #26ACF5;
}
.status2{
  color: #26ACF5;
}
.status3 {
  color: #40ae36;
}
</style>
